package com.zxl.soft.generator.test.service.impl;

import com.zxl.soft.generator.test.entity.ChineseWord;
import com.zxl.soft.generator.test.mapper.ChineseWordMapper;
import com.zxl.soft.generator.test.service.ChineseWordService;
import com.zxl.soft.generator.test.param.ChineseWordQueryParam;
import com.zxl.soft.generator.test.vo.ChineseWordQueryVo;
import com.zxl.soft.generator.common.service.impl.BaseServiceImpl;
import com.zxl.soft.generator.common.vo.Paging;
import com.zxl.soft.generator.test.param.ChineseWordQueryNonePageParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.io.Serializable;
import java.util.List;


/**
 * <pre>
 *  服务实现类
 * </pre>
 *
 * @author zhaoxl
 * @since 2021-08-12
 */
@Slf4j
@Service
public class ChineseWordServiceImpl extends BaseServiceImpl<ChineseWordMapper, ChineseWord> implements ChineseWordService {

    @Autowired
    private ChineseWordMapper chineseWordMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveChineseWord(ChineseWord chineseWord) throws Exception {
        return super.save(chineseWord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateChineseWord(ChineseWord chineseWord) throws Exception {
        return super.updateById(chineseWord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteChineseWord(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public ChineseWordQueryVo getChineseWordById(Serializable id) throws Exception {
        return chineseWordMapper.getChineseWordById(id);
    }

    @Override
    public Paging<ChineseWordQueryVo> getChineseWordPageList(ChineseWordQueryParam chineseWordQueryParam) throws Exception {
        Page page = setPageParam(chineseWordQueryParam, OrderItem.desc("id"));
        IPage<ChineseWordQueryVo> iPage = chineseWordMapper.getChineseWordPageList(page, chineseWordQueryParam);
        return new Paging(iPage);
    }

    @Override
    public List<ChineseWordQueryVo> getChineseWordList(ChineseWordQueryNonePageParam chineseWordQueryNonePageParam) throws Exception {
        return chineseWordMapper.getChineseWordList(chineseWordQueryNonePageParam);
    }

}
